package com.example.stars_project_android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.stars_project_android.R;
import com.example.stars_project_android.entity.Collections;
import com.example.stars_project_android.entity.SpaceTime;

import java.util.List;

/**
 * 首页房间的适配器
 */
public class GvAdapter extends BaseAdapter {

    private Context context;
    private int item;
    private List<SpaceTime> dataSource;
    //声明列表项中的控件
    public GvAdapter(Context context,int item,List<SpaceTime> dataSource){
        //上下文环境
        this.context = context;
        //列表项布局文件ID
        this.item = item;
        //数据源
        this.dataSource=dataSource;
    }
    @Override
    public int getCount() {
        if (dataSource != null){
            return dataSource.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (dataSource != null){
            return dataSource.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // 加载布局文件
        if(null==convertView){
            convertView = LayoutInflater.from(context).inflate(item,null);
        }
        // 接下来先获取布局文件中的控件对象
        TextView title = convertView.findViewById(R.id.txt_icon);
        // 给数据项填充数据
        title.setText(dataSource.get(position).getRoomName());
        return convertView;
    }
}
